//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int c, b, i, j, k, x;
bool a[35001];
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%d%d", &c, &b);
	memset(a,0,sizeof(a));
	a[0]=1;
	
	for(k=0;k<b;++k){
		scanf("%d", &x);
		for(j=c-x;j>=0;--j){
			if(a[j])a[j+x]=1;
		}
	}
	for(j=c;!a[j];--j);
	printf("%d\n", j);
	return 0;
}
